package cn.yerly.sakura.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import cn.yerly.sakura.domain.util.CustomLocalDateSerializer;
import cn.yerly.sakura.domain.util.ISO8601LocalDateDeserializer;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Type;
import org.joda.time.LocalDate;
import org.springframework.data.elasticsearch.annotations.Document;

import javax.persistence.*;
import javax.validation.constraints.*;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import java.util.Objects;

/**
 * A TradeStateChangelog.
 */
@Entity
@Table(name = "TRADESTATECHANGELOG")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Document(indexName="tradestatechangelog")
public class TradeStateChangelog implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @NotNull
    @Column(name = "type", nullable = false)
    private Integer type;

    @NotNull
    @Column(name = "old_state", nullable = false)
    private Integer oldState;

    @NotNull
    @Column(name = "new_state", nullable = false)
    private Integer newState;

    @NotNull
    @Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDate")
    @JsonSerialize(using = CustomLocalDateSerializer.class)
    @JsonDeserialize(using = ISO8601LocalDateDeserializer.class)
    @Column(name = "ctime", nullable = false)
    private LocalDate ctime;

    @Column(name = "disabled")
    private Boolean disabled;

    @OneToOne
    private Trade trade;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public Integer getOldState() {
        return oldState;
    }

    public void setOldState(Integer oldState) {
        this.oldState = oldState;
    }

    public Integer getNewState() {
        return newState;
    }

    public void setNewState(Integer newState) {
        this.newState = newState;
    }

    public LocalDate getCtime() {
        return ctime;
    }

    public void setCtime(LocalDate ctime) {
        this.ctime = ctime;
    }

    public Boolean getDisabled() {
        return disabled;
    }

    public void setDisabled(Boolean disabled) {
        this.disabled = disabled;
    }

    public Trade getTrade() {
        return trade;
    }

    public void setTrade(Trade trade) {
        this.trade = trade;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        TradeStateChangelog tradeStateChangelog = (TradeStateChangelog) o;

        if ( ! Objects.equals(id, tradeStateChangelog.id)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(id);
    }

    @Override
    public String toString() {
        return "TradeStateChangelog{" +
                "id=" + id +
                ", type='" + type + "'" +
                ", oldState='" + oldState + "'" +
                ", newState='" + newState + "'" +
                ", ctime='" + ctime + "'" +
                ", disabled='" + disabled + "'" +
                '}';
    }
}
